home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / ACKSRC.ZIP / ACKASM.ASM < prev    next >
Assembly Source File  |  1993-06-20  |  16KB  |  639 lines

  1. PAGE 80,132
  2. TITLE - XTASM.ASM - Assembly routines for 3D engine
  3. ;;;.286P
  4. ;==============================================================================
  5. ; COMMAND LINE ASSEMBLY
  6. ;    MASM /B63 /Z /D_Mx FILENAME;
  7. ;
  8. ;  WHERE Mx SPECIFIES MODEL (l OR c) FOR LARGE OR COMPACT MODELS
  9. ;==============================================================================
  10.     INCLUDE        ET.EQU
  11.     INCLUDE        ET.MAC
  12.  
  13.     ANGLE_30    equ        160
  14.     ANGLE_360   equ        1920
  15.  
  16.     extrn    _bMaps:DWORD
  17.     extrn    _oMaps:DWORD
  18.     extrn    _bdfp:DWORD
  19.     extrn    _PageBegin:WORD
  20.     extrn    _InvCosTable:DWORD
  21.     extrn    _InvSinTable:DWORD
  22.     extrn    _LongCosTable:DWORD
  23.     extrn    _DistanceTable:WORD
  24.     extrn    _AdjustTable:DWORD
  25.     extrn    _CenterRow:WORD
  26.     extrn    _MaxDistance:WORD
  27.     extrn    _TopColor:WORD
  28.     extrn    _BottomColor:WORD
  29.  
  30.     extrn    _lowmask:BYTE
  31.     extrn    _Walls:WORD
  32.  
  33.  
  34.     extrn    _xRay:NEAR
  35.     extrn    _yRay:NEAR
  36.     extrn    N_LDIV@:FAR
  37.  
  38.  
  39.     PUBLIC        _graphinit
  40.     PUBLIC        _usepage
  41.     PUBLIC        _flippage
  42.     PUBLIC        _SetPalette
  43.     PUBLIC        _DrawWalls
  44.     PUBLIC        _DrawOneObject
  45.  
  46. SC_INDEX equ    03c4h    ;Sequence Controller Index
  47. CRTC_INDEX equ    03d4h    ;CRT Controller Index
  48. MISC_OUTPUT equ 03c2h    ;Miscellaneous Output register
  49. SCREEN_SEG equ    0a000h    ;segment of display memory in mode X
  50.  
  51.  
  52. _TEXT    segment byte public 'CODE'
  53. DGROUP    group    _DATA,_BSS
  54.     assume    cs:_TEXT,ds:DGROUP
  55. _ViewPage  dw 0 ; The address of the current view page
  56. _WritePage dw 0 ; The address of the current write page
  57. PageTable dw 4 dup (0)     ; Address of 4 pages
  58. ScreenWidth dw 320/4     ; The width of the screen
  59. PageSize    dw 320/4*240 ; The size of each page
  60. CRTParms label    word
  61.           dw      00d06h  ;vertical total
  62.           dw      03e07h  ;overflow (bit 8 of vertical counts)
  63.           dw      04209h  ;cell height (2 to double-scan)
  64.           dw      0ea10h  ;v sync start
  65.           dw      0ac11h  ;v sync end and protect cr0-cr7
  66.           dw      0df12h  ;vertical displayed
  67.           dw      00014h  ;turn off dword mode
  68.           dw      0e715h  ;v blank start
  69.           dw      00616h  ;v blank end
  70.           dw      0e317h  ;turn on byte mode
  71. CRT_PARM_LENGTH equ    (($-CRTParms)/2)
  72.  
  73. _TEXT    ends
  74. _DATA    segment word public 'DATA'
  75. ; Index/data pairs for CRT Controller registers that differ between
  76. ; mode 13h and mode X.
  77. _d@    label    byte
  78. _DATA    ends
  79. _BSS    segment word public 'BSS'
  80. _b@    label    byte
  81. _BSS    ends
  82.  
  83.  
  84. public _graphinit
  85. public _ViewPage,_WritePage
  86. public ScreenWidth,PageSize,PageTable
  87.  
  88.  
  89. _TEXT    SEGMENT byte public 'CODE'
  90.     ASSUME cs:_TEXT
  91.  
  92. ;==============================================================================
  93. ; void graphinit(int width,int psize,int mask)
  94. ;   width - width of the screen in bytes/plane (defaults to 320/4 if 0)
  95. ;   psize - size of each page in bytes/plane (defaults to 320*200/4 if 0)
  96. ;==============================================================================
  97. PBEGIN     _graphinit
  98.      push bp
  99.      mov bp,sp
  100.      push si
  101.      push di
  102.      push ds
  103.  
  104.      mov ax,cs
  105.      mov ds,ax
  106.      mov es,ax
  107.  
  108.      mov bx,320/4
  109.      mov cs:[ScreenWidth],bx
  110.      mov bx,320/4*240
  111.     mov cs:[PageSize],bx
  112.  
  113.     ; Set up the page table
  114.  
  115.     xor ax,ax
  116.     mov bx,cs:[PageSize]
  117.     lea di,cs:[PageTable]
  118.     mov cx,4
  119. init4:
  120.     stosw
  121.     add ax,bx
  122.     loop init4
  123.  
  124.  
  125. ; Now set up the graphics mode
  126.  
  127.     mov ax,13h
  128.     int 10h ; Set 320x200x256
  129.  
  130.     mov    dx,3d4h
  131.     mov    al,13h
  132.     out    dx,al
  133.     inc    dx
  134.     mov    al,2dh        ;Set bytes per line at 90
  135.     out    dx,al
  136.  
  137.     mov    dx,3c4h
  138.     mov    al,4
  139.     out    dx,al
  140.     inc    dx
  141.     in    al,dx
  142.     and    al,0f7h        ;Turn off chain4 mode
  143.     out    dx,al
  144.  
  145.     mov    dx,3d4h
  146.     mov    al,17h
  147.     out    dx,al
  148.     inc    dx
  149.     in    al,dx
  150.     or    al,40h        ;Turn on byte mode
  151.     out    dx,al
  152.  
  153.     mov    dx,3d4h
  154.     mov    al,14h
  155.     out    dx,al
  156.     inc    dx
  157.     in    al,dx
  158.     and    al,0bfh        ;Turn off double-word mode
  159.     out    dx,al
  160.  
  161.     mov    dx,3dah
  162.     in    al,dx
  163.     mov    dx,3c0h
  164.     mov    al,30h        ;Select Attribute index 10h
  165.     out    dx,al
  166.     mov    al,71h        ;Turn on PCS, PPC and G/A
  167.     out    dx,al
  168.  
  169.     mov ax,SCREEN_SEG ;now clear all display memory, 8 pixels
  170.     mov es,ax          ; at a time
  171.     sub di,di    ;point ES:DI to display memory
  172.     sub ax,ax    ;clear to zero-value pixels
  173.     mov cx,8000h ;# of words in display memory
  174.     rep stosw    ;clear all of display memory
  175.  
  176.     pop ds
  177.     pop di    ;restore C register vars
  178.     pop si
  179.     pop bp    ;restore caller's stack frame
  180.     ret
  181. _graphinit endp
  182.  
  183. ;==============================================================================
  184. ; void SetVGAmode(void);
  185. ;==============================================================================
  186. PBEGIN    _SetVGAmode
  187.     push    bp
  188.     mov    ax,13h
  189.     int    10h        ; Set 320x200x256
  190.     pop    bp
  191.     ret
  192. _SetVGAmode endp
  193.  
  194. ;==============================================================================
  195. ; void usepage(int page)
  196. ;==============================================================================
  197. UPnum    equ    [bp+ABASE]
  198.  
  199. PBEGIN    _usepage
  200.     push bp
  201.     mov bp,sp
  202.     mov bx,UPnum
  203.     and bx,3
  204.     shl bx,1
  205.     mov ax,cs:PageTable[bx]
  206.     mov cs:[_WritePage],ax
  207.     pop bp
  208.     ret
  209. _usepage endp
  210.  
  211. ;==============================================================================
  212. ; void flippage()
  213. ;
  214. ; NOTE: Some lines have been commented out for test purposes. If you experience
  215. ;    flicker when the page flips, un-comment the lines waiting for vertical
  216. ;    retrace.
  217. ;==============================================================================
  218. PBEGIN    _flippage
  219.     mov cx,cs:[_ViewPage]
  220.     xchg cx,cs:[_WritePage]
  221.     mov cs:[_ViewPage],cx ; An ISR will set the VGA at the next retrace
  222.  
  223.     mov  bh,0dH
  224.     mov  bl,cl
  225.     mov dx,3dah
  226.  
  227. Ret1:
  228. ;;;;    in al,dx
  229. ;;;;    test al,1
  230. ;;;;    jnz Ret1 ; Wait for display enable
  231.  
  232.  
  233.  
  234. ;    cli
  235.     mov al,0ch
  236.     mov ah,ch
  237.     mov dx,3d4h
  238.     out dx,ax    ; set the displayed offset (high)
  239. ;    inc al
  240. ;    mov ah,cl
  241. ;;;    mov ax,bx
  242. ;;;    out dx,ax    ; set the displayed offset (low)
  243. ;    sti
  244.  
  245. ;;    mov dx,3dah
  246. Ret2:
  247. ;;    in al,dx
  248. ;;    test al,8
  249. ;;    jz Ret2 ; Wait for the video card to use the address just set
  250.  
  251.     ret
  252. _flippage endp
  253.  
  254.  
  255. ;==============================================================================
  256. ; void SetPalette(unsigned char far *PalBuf);
  257. ;==============================================================================
  258. SPbuf    equ    [bp+ABASE]
  259.  
  260. PBEGIN    _SetPalette
  261.     push    bp
  262.     mov    bp,sp
  263.     push    ds
  264.     push    si
  265.  
  266.     lds    si,dword ptr SPbuf
  267.     mov    cx,256
  268.     xor    bx,bx
  269.     cld
  270.     mov    dx,3C8H
  271. sp010:
  272.     mov    al,bl
  273.     out    dx,al
  274.     inc    dx
  275.     lodsb
  276.     out    dx,al
  277.     lodsb
  278.     out    dx,al
  279.     lodsb
  280.     out    dx,al
  281.     dec    dx
  282.     inc    bx
  283.     loop    sp010
  284.  
  285.     pop    si
  286.     pop    ds
  287.     pop    bp
  288.     ret
  289. _SetPalette endp
  290.  
  291. ;==============================================================================
  292. ; void DrawWalls(void);
  293. ;==============================================================================
  294. Y2    equ    [bp-2]
  295. AVLOW    equ    [bp-4]
  296. AVHI    equ    [bp-6]
  297. VCOL    equ    [bp-8]
  298. BOFFLOW equ    [bp-10]
  299. BOFFHI    equ    [bp-12]
  300. sColor    equ    [bp-14]
  301. fColor    equ    [bp-16]
  302.  
  303. PBEGIN    _DrawWalls
  304.     push    bp
  305.     mov    bp,sp
  306.     sub    sp,18
  307.     push    ds
  308.     push    si
  309.     push    di
  310.  
  311.     mov    dx,3c4H
  312.     mov    ax,0F02H
  313.     out    dx,ax            ;Select map mask and all planes
  314.  
  315.     mov    bx,word ptr DGROUP:_MaxDistance ; Get max distance to wall
  316.     shl    bx,1            ; Make a word index
  317.     mov    ax,word ptr DGROUP:_DistanceTable[bx] ;Look up actual height
  318.     cmp    ax,200            ; Full screen height?
  319.     jae    drw000            ; Yes, nothing to fill in
  320.  
  321.     and    ax,0FFFEH        ; Strip any odd values
  322.     mov    bx,ax            ; Save height
  323.     mov    si,ax            ; Again save height
  324.     shr    bx,1            ; Get Height / 2
  325.     mov    dx,100            ; Pick up our center row
  326.     sub    dx,bx            ; and sub ht/2
  327.     mov    bx,dx            ; Save new value
  328.  
  329.     mov    ax,90
  330.     imul    dx
  331.     mov    bx,ax
  332.     mov    ax,90
  333.     imul    si
  334.     mov    si,ax
  335.  
  336. ;    mov    cl,6            ; Get ready to mult by 80
  337. ;    shl    bx,cl            ; first mult by 64
  338. ;    shl    si,cl            ; also mult the original ht
  339. ;    mov    cl,4            ; No do a mult by 16
  340. ;    shl    dx,cl            ; to top layer
  341. ;    shl    ax,cl            ; and initial height
  342. ;    add    bx,dx            ; Add x64 and x16 for x80
  343. ;    add    si,ax            ; do same with height
  344.  
  345.     mov    ax,0A000H
  346.     mov    es,ax
  347.     mov    di,cs:_WritePage    ;get start of buffer
  348.  
  349.     mov    ax,ds:_TopColor
  350.     mov    ah,al
  351.     shr    bx,1            ;only fill words
  352.     mov    cx,bx            ;get amount to fill in
  353.   rep    stosw
  354.     add    di,si            ;then skip amount of wall
  355.     mov    ax,ds:_BottomColor
  356.     mov    ah,al
  357.     mov    cx,bx
  358.   rep    stosw
  359.  
  360.  
  361. drw000:
  362.     xor    bx,bx            ;Initial loop/plane counter
  363.  
  364. drw010:
  365.     push    bx            ;save loop/plane counter
  366.     mov    VCOL,bx            ;Set beginning video column
  367.     mov    dx,3c5H
  368.     mov    al,byte ptr DGROUP:_lowmask[bx]
  369.     out    dx,al            ;select mask to write to
  370.